package com.fz.us.oa.core.dao.com.impl;

import com.fz.us.admin.company.dao.impl.BaseFlowDaoImpl;
import com.fz.us.admin.dict.entity.DictItem;
import com.fz.us.admin.dict.service.DictItemService;
import com.fz.us.base.bean.BaseEnum;
import com.fz.us.oa.core.dao.com.ResidentDao;
import com.fz.us.oa.core.entity.com.Resident;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by dzw on 2018/3/13.
 */
@Repository
public class ResidentDaoImpl extends BaseFlowDaoImpl<Resident, String> implements ResidentDao {

    @Autowired
    private DictItemService dictItemService;

    @Override
    public Resident getByName(String residentName) {
        List<Resident> residentList = getSession().createQuery("from Resident r where r.name=?")
                .setParameter(0, residentName)
                .list();
        if(residentList.size()>0){
            return residentList.get(0);
        }else{
            return null;
        }
    }

    @Override
    public List<Resident> getResidentByStreet(DictItem street) {
        List<Resident> residentList = getSession().createQuery("from Resident r where r.state=? and r.street=?")
                .setParameter(0, BaseEnum.StateEnum.Enable)
                .setParameter(1, street)
                .list();
        return residentList;
    }

    @Override
    public DictItem getStreetByNo(int streetNo) {
        List<DictItem> streetList = getSession().createQuery("from DictItem d where d.value=?")
                .setParameter(0, "street"+streetNo)
                .list();
        if(streetList.size()>0){
            return streetList.get(0);
        }else{
            return null;
        }
    }
}
